package cn.ciis.sys.account;

import cn.ciis.basic.base.BaseValidator;
import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;

/**
 * AccountUpdateValidator 验证账号修改功能表单
 *
 * @author 冉志林
 */
public class AccountUpdateValidator extends BaseValidator {

  @Override
  protected void validate(Controller c) {
    setShortCircuit(true);

    /** 验证 userName */
    validateRequired("account.fullName", "msg", "姓名不能为空");

    validateRequired("account.mobile", "msg", "手机号码不能为空");
    validateRequired("account.email", "msg", "邮箱不能为空");
    validateMobilePattern("account.mobile");

    if (StrKit.notBlank(c.getPara("account.password"))) {
      validateStrongPassword("account.password");
    }
  }

  @Override
  protected void handleError(Controller c) {
    c.setAttr("state", "fail");
    c.renderJson();
  }
}
